<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>进度条</title>
    <style>
    .con {
        height: 30px;
        width: 500px;
        margin: 0 auto;
        background: #eee
    }
    .pg{
        height: 30px;
        background: red;
        width: 100px;
    }
    </style>
</head>
<body>
    <div class="con" id="con">
        <div class="pg" id="pg" style="width: 0;"></div>

    </div>
    <button id="start">开始</button>
    <button id="pause">暂停</button>
</body>
<script>
    var con = document.getElementById("con");
    var pg = document.getElementById("pg");
    var start = document.getElementById("start");
    var pause = document.getElementById("pause");
    var intervalId;
    start.onclick = function(){
        intervalId = setInterval(function(){
            var width = pg.style.width;
            width = parseInt(width) + 1;
            pg.style.width = width + "px";
            if(width == 500){
                clearInterval(intervalId);
            }
        }, 100)
    }
    //暂停操作
    pause.onclick = function(){
        clearInterval(intervalId);
    }
    
</script>
</html>